package org.zcl.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.zcl.constant.RedisKey;
import org.zcl.entity.RankRequest;
import org.zcl.entity.RankResponse;
import org.zcl.service.RankService;
import org.zcl.utils.RedisHelper;

import java.util.List;

/**
 * .
 *
 * @author zhuchenglin
 * @since 2024/4/22 16:31
 */
@Service
public class RankServiceImpl implements RankService {

    @Autowired
    private RedisHelper redisHelper;

    @Override
    public RankResponse add(RankRequest request) {
        Long userId = request.getUserId();
        Long score = redisHelper.incrementScore(RedisKey.RANK_TAG, userId);
        return new RankResponse(request.getUserId(), score);
    }

    @Override
    public List<RankResponse> rankList() {
        return redisHelper.list(RedisKey.RANK_TAG);
    }
}
